package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.ProductListView;
import com.boc.langxiang.entity.request.ProductListRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.ProductListContent;
import com.boc.langxiang.entity.response.ProductListContent2;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/6/28.
 */
public class ProductListPresenter extends SuperPresenter {
    private ProductListView mView;
    public ProductListPresenter(ProductListView view) {
        super(view);
        this.mView = view;
    }

    public void getList(ProductListRequest request){
        mView.showLoading();
        mService.getProductsList(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ProductListContent2>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ProductListContent2> response) {
                        mView.getListSuccsee(response.getContent().getResult());
                    }
                });
    }

    public void loadMore(ProductListRequest request){
        mService.getProductsList(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ProductListContent2>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ProductListContent2> response) {
                        mView.loadMoreSuccess(response.getContent().getResult());
                    }
                });
    }
}
